package com.jeesite.modules.task.deploy.service;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.service.CrudService;
import com.jeesite.common.service.ServiceException;
import com.jeesite.common.utils.excel.ExcelImport;
import com.jeesite.common.validator.ValidatorUtils;
import com.jeesite.modules.backlog.entity.DcSupBacklog;
import com.jeesite.modules.backlog.service.DcSupBacklogService;
import com.jeesite.modules.common.dao.SysBasicDao;
import com.jeesite.modules.common.entity.SysBasicUser;
import com.jeesite.modules.common.service.SysMsgService;
import com.jeesite.modules.common.service.SysOfficeUnitService;
import com.jeesite.modules.file.utils.FileUploadUtils;
import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.entity.Office;
import com.jeesite.modules.sys.utils.DictUtils;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.task.action.dao.DcSupTaskActionDao;
import com.jeesite.modules.task.action.entity.DcSupTaskAction;
import com.jeesite.modules.task.audit.service.DcSupTaskAuditService;
import com.jeesite.modules.task.deploy.dao.DcSupTaskInfoAddDao;
import com.jeesite.modules.task.deploy.dao.DcSupTaskInfoDao;
import com.jeesite.modules.task.deploy.dao.DcSupTaskInfoSyncDao;
import com.jeesite.modules.task.deploy.entity.*;
import com.jeesite.modules.task.dict.entity.DcSupTaskInfoDict;
import com.jeesite.modules.task.dict.service.DcSupTaskInfoDictService;
import com.jeesite.modules.task.feedback.dao.DcSupTaskFeedbackDao;
import com.jeesite.modules.task.feedback.entity.DcSupTaskFeedback;
import com.jeesite.modules.task.status.service.DcSupTaskStatusService;
import com.jeesite.modules.utils.DateTimeUtil;
import com.jeesite.modules.utils.Dict;
import com.jeesite.modules.utils.OfficeUtil;
import com.jeesite.modules.yzw.entity.MsgDetail;
import com.jeesite.modules.yzw.service.LehandYzwPushTask;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 任务部署信息表(主)Service
 * @author zrr
 * @version 2022-03-02
 */
@Service
@Transactional(readOnly=false)
public class DcSupTaskInfoService extends CrudService<DcSupTaskInfoDao, DcSupTaskInfo> {

	@Autowired
	private DcSupTaskActionDao dcSupTaskActionDao;
	@Autowired
	private DcSupTaskInfoAddDao dcSupTaskInfoAddDao;
	@Autowired
	private DcSupTaskFeedbackDao dcSupTaskFeedbackDao;
	@Autowired
	@Lazy
	private DcSupTaskAuditService dcSupTaskAuditService;
	@Autowired
	private DcSupTaskStatusService dcSupTaskStatusService;
	@Autowired
	private SysOfficeUnitService sysOfficeUnitService;
	@Autowired
	private LehandYzwPushTask lehandYzwPushTask;
	@Autowired
	private SysBasicDao sysBasicDao;
	@Autowired
	private DcSupTaskInfoDictService dcSupTaskInfoDictService;
	@Autowired
	private DcSupTaskInfoSyncDao dcSupTaskInfoSyncDao;
	@Autowired
	private SysMsgService sysMsgService;
	@Autowired
	private DcSupBacklogService dcSupBacklogService;

	/**
	 * 获取单条数据
	 * @param dcSupTaskInfo
	 * @return
	 */
	@Override
	public DcSupTaskInfo get(DcSupTaskInfo dcSupTaskInfo) {
		DcSupTaskInfo entity = super.get(dcSupTaskInfo);
		if (entity != null){
			// 获取分发任务
			DcSupTaskAction dcSupTaskAction = new DcSupTaskAction(entity.getId());
			dcSupTaskAction.setStatus(DcSupTaskAction.STATUS_NORMAL);
			entity.setDcSupTaskActionList(dcSupTaskActionDao.findList(dcSupTaskAction));
			// 获取反馈列表
			DcSupTaskInfoAdd dcSupTaskInfoAdd = new DcSupTaskInfoAdd();
			dcSupTaskInfoAdd.setTaskId(entity.getId());
			entity.setDcSupTaskInfoAddList(dcSupTaskInfoAddDao.findList(dcSupTaskInfoAdd));

			entity.setTaskStartTimeStr(DateUtils.formatDate(entity.getTaskStartTime(),"yyyy-MM-dd HH:mm"));
			entity.setTaskEndTimeStr(DateUtils.formatDate(entity.getTaskEndTime(),"yyyy-MM-dd HH:mm"));
		}

		return entity;
	}
	
	/**
	 * 查询分页数据
	 * @param dcSupTaskInfo 查询条件
	 * @return
	 */
	@Override
	public Page<DcSupTaskInfo> findPage(DcSupTaskInfo dcSupTaskInfo) {
		return super.findPage(dcSupTaskInfo);
	}
	
	/**
	 * 查询列表数据
	 * @param dcSupTaskInfo
	 * @return
	 */
	@Override
	public List<DcSupTaskInfo> findList(DcSupTaskInfo dcSupTaskInfo) {
		return super.findList(dcSupTaskInfo);
	}
	
	/**
	 * 查询子表分页数据
	 * @param dcSupTaskAction
	 * @return
	 */
	public Page<DcSupTaskAction> findSubPage(DcSupTaskAction dcSupTaskAction) {
		Page<DcSupTaskAction> page = dcSupTaskAction.getPage();
		page.setList(dcSupTaskActionDao.findList(dcSupTaskAction));
		return page;
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param dcSupTaskInfo
	 */
	@SneakyThrows
	@Override
	@Transactional(readOnly=false)
	public void save(DcSupTaskInfo dcSupTaskInfo) {
		// 将审核驳回的单条消息置为已读，需要注意，不是任务部署人也可以再次提交
		sysMsgService.makeMsgReadByBiz(dcSupTaskInfo.getId(), "audit_reject_deploy", null);

		if (dcSupTaskInfo.getDcSupTaskInfoAddList().size() == 0) {
			List<DcSupTaskInfoAdd> list = new ArrayList<>();
			DcSupTaskInfoAdd add = new DcSupTaskInfoAdd();
			add.setFeedbackStartTime(dcSupTaskInfo.getTaskStartTime());
			add.setFeedbackEndTime(dcSupTaskInfo.getTaskEndTime());
			list.add(add);
			dcSupTaskInfo.setDcSupTaskInfoAddList(list);
		}
		Office latestUnit = sysOfficeUnitService.getLatestUnitByOffice();
		if(!StringUtils.equals("999",dcSupTaskInfo.getTaskTypeCode())){
			dcSupTaskInfo.setCreateUnit(latestUnit.getOfficeCode());
			dcSupTaskInfo.setCreateUnitName(latestUnit.getOfficeName());
		}

		uniqueMessageNumber(dcSupTaskInfo);
		if (StringUtils.isNotBlank(dcSupTaskInfo.getAuditorCode())) {
			dcSupTaskInfo.setAuditFlag("1");
		}
		if ("1".equals(dcSupTaskInfo.getTaskStatus())) {
			super.save(dcSupTaskInfo);
			batchSaveTaskAddTime(dcSupTaskInfo);
			// 保存上传图片
			FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_image");
			// 保存上传附件
			FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_file");
			return;
		}
		super.save(dcSupTaskInfo);
		if (StringUtils.isNotBlank(dcSupTaskInfo.getId())) {
			DcSupTaskFeedback deleteFeedback = new DcSupTaskFeedback();
			deleteFeedback.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskFeedbackDao.deleteByEntity(deleteFeedback);
			//插入分解后的反馈时间
			DcSupTaskInfoAdd dcdelete = new DcSupTaskInfoAdd();
			dcdelete.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskInfoAddDao.deleteByEntity(dcdelete);
		}
		// 保存上传图片
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_image");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_file");

		// 设置一个临时变量来记录这条任务放到审核表中时的id，在消息中使用
		String tempAuditId = "";

		//判断是否输入督办单位分为特殊流程，一般流程
		if (StringUtils.isNotBlank(dcSupTaskInfo.getTaskSupOrg())) {
			tempAuditId = IdGen.nextId();
			String secretary_general = dcSupTaskAuditService.addAuditInfo(tempAuditId, dcSupTaskInfo.getId(), dcSupTaskInfo.getId(), Dict.TargetType.TYPE_1, Dict.AuditType.TYPE_2,
					dcSupTaskInfo.getAuditorCode(), dcSupTaskInfo.getAuditorName(), null);
			if (StringUtils.isNotBlank(secretary_general)) {
				throw new Exception("过程审核失败");
			}
		} else {
			//先看是否审核，1，是 0.否
			if (StringUtils.isBlank(dcSupTaskInfo.getAuditorCode())) {
				//直接分发给各个牵头责任单位
				distributeOrgTask(dcSupTaskInfo);
			} else {
				//等待插入数据到过程审核表
				tempAuditId = IdGen.nextId();
				String secretary_general = dcSupTaskAuditService.addAuditInfo(tempAuditId, dcSupTaskInfo.getId(), dcSupTaskInfo.getId(), Dict.TargetType.TYPE_1, Dict.AuditType.TYPE_1,
						dcSupTaskInfo.getAuditorCode(), dcSupTaskInfo.getAuditorName(), null);
				if (StringUtils.isNotBlank(secretary_general)) {
					throw new Exception("过程审核失败");
				}

			}
		}
		batchSaveTaskAddTime(dcSupTaskInfo);

		// 1普任务部署:选择审核人，向审核人发送消息
		// 1秘任务部署编辑提交,向审核人发消息
		if (StringUtils.isNotBlank(dcSupTaskInfo.getAuditorCode())) {
//			PcMsgContent msg = new PcMsgContent();
//			msg.setTitle("提示信息");
//			// 任务部署
//			msg.setContent("您有一个任务:\"" + dcSupTaskInfo.getTaskTitle() + "\"任务部署待审核,请及时查看");
//			msg.addButton("任务部署审核", "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId);
//			MsgPushUtils.push(msg, tempAuditId, "audit_deploy", dcSupTaskInfo.getAuditorCode());
			//发送易政网消息
			MsgDetail msgDetail = new MsgDetail();
			msgDetail.setSendid(UserUtils.getUser().getUserCode());
			msgDetail.setSubjectid(dcSupTaskInfo.getAuditorCode());
			msgDetail.setMesg("您有一个任务:\"" + dcSupTaskInfo.getTaskTitle() + "\"任务部署待审核,请及时登录系统查看");
			lehandYzwPushTask.pushYzwShortMsg(msgDetail);
			//任务发起,创建审核待办
			DcSupBacklog add = dcSupBacklogService.add("督查督办", "任务部署审核", "督办任务部署审核", "提示信息"
					, "您有一个任务:" + dcSupTaskInfo.getTaskTitle() + "任务部署待审核,请及时查看"
					, "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId, ""
					, tempAuditId, "task_audit_deploy", dcSupTaskInfo.getAuditorCode()
					, dcSupTaskInfo.getId(), "");
			// TODO 新增皖政通待办
//			Map<String,String> message = new HashMap<>();
//			message.put("id",add.getId());
//			message.put("title","督办任务部署审核");
//			message.put("message","您有一个任务:" + dcSupTaskInfo.getTaskTitle() + "任务部署待审核,请及时查看");
//			message.put("senderId",UserUtils.getUser().getExtend().getExtendS3());
//			message.put("senderName",UserUtils.getUser().getUserName());
//			String s = dcSupBacklogService.addWZTPending(message,dcSupTaskInfo.getAuditorCode());
//			dcSupBacklogService.updateWZTaddMessage2Bacnklog(add.getId(),s);
			//如果有被驳回的任务 驳回的置为已办
			dcSupBacklogService.doBacklog(dcSupTaskInfo.getId(),"task_deploy");

		}
	}

	public void batchSaveTaskAddTime(DcSupTaskInfo dcSupTaskInfo) {
		//插入分解后的反馈时间
		if(StringUtils.isNotBlank(dcSupTaskInfo.getId())){
		DcSupTaskInfoAdd dcdelete = new DcSupTaskInfoAdd();
		dcdelete.setTaskId(dcSupTaskInfo.getId());
		dcSupTaskInfoAddDao.deleteByEntity(dcdelete);
		}
		for (DcSupTaskInfoAdd dcSupTaskInfoAdd : dcSupTaskInfo.getDcSupTaskInfoAddList()) {
			if (dcSupTaskInfoAdd.getFeedbackStartTime() != null && dcSupTaskInfoAdd.getFeedbackEndTime() != null) {
				dcSupTaskInfoAdd.setTaskId(dcSupTaskInfo.getId());
				dcSupTaskInfoAddDao.insert(dcSupTaskInfoAdd);
			}

		}
	}

	/**
	 * 更新状态
	 * @param dcSupTaskInfo
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(DcSupTaskInfo dcSupTaskInfo) {
		super.updateStatus(dcSupTaskInfo);
	}
	
	/**
	 * 删除数据
	 * @param dcSupTaskInfo
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(DcSupTaskInfo dcSupTaskInfo) {
		DcSupTaskInfo dcSupTaskInfo_ = get(dcSupTaskInfo);
		super.delete(dcSupTaskInfo);

	}

	public Page<DcSupTaskInfo> findListPage(DcSupTaskInfo dcSupTaskInfo) {
		Page<DcSupTaskInfo> page = dcSupTaskInfo.getPage();
		page.setList(dao.findListPage(dcSupTaskInfo));
		return  page;
	}

	public List<DcSupTaskInfoAdd> getMutiFeedBackTimes(DcSupTaskInfo dcSupTaskInfo) throws ParseException {
		//定义集合装反馈的时间段，返回给前台展示
		List<DcSupTaskInfoAdd> dcSupTaskFeedbackList = new ArrayList<>();
		//判断是多次反馈还是单次反馈
			//判断多次反馈的起始结束时间、反馈方式、反馈频次全部不能为空，前台已做判断，后台做二次判断保险点
			if(dcSupTaskInfo.getTaskStartTime()!=null&&dcSupTaskInfo.getTaskEndTime()!=null&&StringUtils.isNotBlank(dcSupTaskInfo.getFeedbackWay())&&StringUtils.isNotBlank(dcSupTaskInfo.getFeedbackRate())){
				//调用计算时间方式，得出反馈时间段的截止时间
				List<String> feedbackTimeList = feedBackTimeMethods(dcSupTaskInfo.getFeedbackWay(),
						dcSupTaskInfo.getFeedbackRate(), DateUtils.formatDate(dcSupTaskInfo.getTaskStartTime(), "yyyy-MM-dd"), DateUtils.formatDate(dcSupTaskInfo.getTaskEndTime(), "yyyy-MM-dd"));
				if (feedbackTimeList.size() == 0) {

				}else if(feedbackTimeList.size() == 1){
					DcSupTaskInfoAdd DcSupTaskFeedback = new DcSupTaskInfoAdd();
					DcSupTaskFeedback.setFeedbackStartTime(dcSupTaskInfo.getTaskStartTime());
					DcSupTaskFeedback.setFeedbackEndTime(dcSupTaskInfo.getTaskEndTime());
					dcSupTaskFeedbackList.add(DcSupTaskFeedback);
				}else if(feedbackTimeList.size()> 1){

					List<String> feedbackStartDateList = getFeedbackStartDateList(feedbackTimeList);
					for (int i = 0; i <feedbackTimeList.size() ; i++) {
						DcSupTaskInfoAdd dcSupTaskFeedback = new DcSupTaskInfoAdd();
						if(i==0){
							dcSupTaskFeedback.setFeedbackStartTime(dcSupTaskInfo.getTaskStartTime());
						}else{
							dcSupTaskFeedback.setFeedbackStartTime(DateUtils.parseDate(feedbackStartDateList.get(i-1),"yyyy-MM-dd"));
						}

						if(i==feedbackTimeList.size()-1){
							dcSupTaskFeedback.setFeedbackEndTime(dcSupTaskInfo.getTaskEndTime());
						}else{
							// 获取结束时间的时分
							String timeOfTaskEndTime = DateUtils.formatDate(dcSupTaskInfo.getTaskEndTime(), "HH:mm:ss").substring(0,5);
							dcSupTaskFeedback.setFeedbackEndTime(DateUtils.parseDate(feedbackTimeList.get(i)+" "+timeOfTaskEndTime,"yyyy-MM-dd HH:mm"));
						}
						dcSupTaskFeedbackList.add(dcSupTaskFeedback);
					}
				}
			}

		dcSupTaskFeedbackList.forEach(add -> {
			add.setFeedbackStartTimeStr(DateUtils.formatDate(add.getFeedbackStartTime(), "yyyy-MM-dd HH:mm"));
			add.setFeedbackEndTimeStr(DateUtils.formatDate(add.getFeedbackEndTime(), "yyyy-MM-dd HH:mm"));
		});
		return dcSupTaskFeedbackList;
	}

	private List<String>  getFeedbackStartDateList(List<String> feedBackTimeList) throws ParseException {
		List<String>  feedbackStartDateList = new ArrayList();
		for (int i = 0; i <feedBackTimeList.size() ; i++) {
			String feedBackTime = feedBackTimeList.get(i);
			Date dd = DateUtils.parseDate(feedBackTime,"yyyy-MM-dd");
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(dd);
			calendar.add(Calendar.DAY_OF_MONTH, 1);//加一天
			feedbackStartDateList.add(DateUtils.formatDate(calendar.getTime()));
		}
		Collections.sort(feedbackStartDateList);
		return feedbackStartDateList;
	}
	public List feedBackTimeMethods(String feedbackRequirements,String feedbackRate,String feedbackStartDate,String feedbackEndDate) throws ParseException {
		//1、考虑时间非空并格式化
		//2、通过反馈方式、频次输出时间
		//开始时间
		String startTime =feedbackStartDate;
		//结束时间
		String endTime = feedbackEndDate;
		//反馈方式
		String taskFrequency = feedbackRequirements;
		//反馈那一天
		String taskFeedbackTime = feedbackRate;
		//actionTimes
		List<String> actionTimesList = new ArrayList<>();
		//无
		if ("0".equals(taskFrequency)) {
			//天
		} else if ("9".equals(taskFrequency)) {
			Long start = DateUtils.parseDate(startTime).getTime();
			Long end = DateUtils.parseDate(endTime).getTime();
			Long oneDay = 1000 * 60 * 60 * 24L;
			Long time = start;
			while (time <= end) {
				Date d = new Date(time);
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				String ds = df.format(d);
				Calendar cal = Calendar.getInstance();
				cal.setTime(d);
				if ("2".equals(taskFeedbackTime) && !(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {
					actionTimesList.add(ds);
				}
				if ("1".equals(taskFeedbackTime)) {
					actionTimesList.add(ds);
				}
				time += oneDay;
			}
			//周
		} else if ("3".equals(taskFrequency)) {
			Long start = DateUtils.parseDate(startTime).getTime();
			Long end = DateUtils.parseDate(endTime).getTime();
			Long oneDay = 1000 * 60 * 60 * 24L;
			Long time = start;
			while (time <= end) {
				Date d = new Date(time);
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				String ds = df.format(d);
				Calendar cal = Calendar.getInstance();
				cal.setTime(d);
				if ("1".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY)) {
					actionTimesList.add(ds);
				}
				if ("2".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY)) {
					actionTimesList.add(ds);
				}
				if ("3".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)) {
					actionTimesList.add(ds);
				}
				if ("4".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY)) {
					actionTimesList.add(ds);
				}
				if ("5".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY)) {
					actionTimesList.add(ds);
				}
				if ("6".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {
					actionTimesList.add(ds);
				}
				if ("7".equals(taskFeedbackTime) && (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {
					actionTimesList.add(ds);
				}
				if(time.longValue()==end.longValue()){
					int dd = cal.get(Calendar.DAY_OF_WEEK);
					if(dd<=Integer.parseInt(taskFeedbackTime)){
						actionTimesList.add(ds);
					}
				}
				time += oneDay;
			}
			//添加最后一个反馈时间段
			if(actionTimesList.size()>0&&DateUtils.parseDate(actionTimesList.get(actionTimesList.size()-1)).getTime()<DateUtils.parseDate(endTime).getTime()){
				actionTimesList.add(endTime);
			}
			//月
		} else if ("2".equals(taskFrequency)) {
			List<String> month = new ArrayList<>();
			month.add(taskFeedbackTime);
			List<LocalDate> timelocalList = getLocalDateListByMonth(date2LocalDate(DateUtils.parseDate(startTime)), date2LocalDate(DateUtils.parseDate(endTime)), month);

			for (int i = 0; i < timelocalList.size(); i++) {
				actionTimesList.add(DateUtils.formatDate(localDate2Date(timelocalList.get(i))));
			}
			//添加最后一个反馈时间段
			if(actionTimesList.size()>0&&DateUtils.parseDate(actionTimesList.get(actionTimesList.size()-1)).getTime()<DateUtils.parseDate(endTime).getTime()){
				actionTimesList.add(endTime);
			}
			String tempendTime=endTime.substring(0,endTime.lastIndexOf("-")+1)+taskFeedbackTime;
			if(DateUtils.parseDate(tempendTime).getTime()> DateUtils.parseDate(endTime).getTime()){
				actionTimesList.add(endTime);
			}
			//季度
		} else if ("1".equals(taskFrequency)) {
			List<String> temp = getRangeSet(startTime, endTime, taskFeedbackTime);
			for (int i = 0; i < temp.size(); i++) {
				actionTimesList.add(temp.get(i));
			}
			//添加最后一个反馈时间段
			if(temp.size()>0&&DateUtils.parseDate(actionTimesList.get(actionTimesList.size()-1)).getTime()<DateUtils.parseDate(endTime).getTime()){
				actionTimesList.add(endTime);
			}
			String tempendTime=endTime.substring(0,endTime.lastIndexOf("-")+1)+taskFeedbackTime;
			if(DateUtils.parseDate(tempendTime).getTime()> DateUtils.parseDate(endTime).getTime()){
				actionTimesList.add(endTime);
			}
		}
		//得到反馈时间与估计时间去重
		Set set = new HashSet(actionTimesList);
		actionTimesList.clear();
		//去重
		actionTimesList.addAll(set);
		Collections.sort(actionTimesList);
		return actionTimesList;
	}

	public static List<LocalDate> getLocalDateListByMonth(LocalDate startDate, LocalDate endDate, List<String> months) {
		List<LocalDate> localDateList = new ArrayList<>();
		LocalDate localDate;
		for (String month : months) {
			LocalDate tempDate = startDate;
			while (tempDate.isBefore(endDate) || tempDate.getMonthValue() == endDate.getMonthValue()) {
				if (tempDate.lengthOfMonth() >= Integer.valueOf(month)) {
					localDate = tempDate.withDayOfMonth(Integer.valueOf(month));
					if (localDate.isAfter(startDate) || localDate.isEqual(startDate)) {
						localDate = tempDate.withDayOfMonth(Integer.valueOf(month));
						if (localDate.isEqual(endDate) || localDate.isBefore(endDate)) {
							localDateList.add(localDate);
						}
					}
				}
				tempDate = tempDate.plusMonths(1);
			}
		}
		return localDateList;
	}
	public static LocalDate date2LocalDate(Date date) {
		if (null == date) {
			return null;
		}
		return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
	}
	public static Date localDate2Date(LocalDate localDate) {
		if (null == localDate) {
			return null;
		}
		ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
		return Date.from(zonedDateTime.toInstant());
	}
	public static List<String> getRangeSet(String beginDate, String endDate, String taskFeedbackTime) throws ParseException {
        /*Date1.after(Date2),当Date1大于Date2时，返回TRUE，当小于等于时，返回false；
          Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false；
          如果业务数据存在相等的时候，而且相等时也需要做相应的业务判断或处理时，你需要使用：！Date1.after(Date2);*/
		List<String> rangeSet = null;
		SimpleDateFormat sdf = null;
		SimpleDateFormat sdf2 = null;
		Date beginDateTime = null;
		Date endDateTime = null;
		rangeSet = new ArrayList<String>();
		sdf = new SimpleDateFormat("yyyy-MM");
		sdf2 = new SimpleDateFormat("yyyy");
		try {
			//定义起始日期
			beginDateTime = sdf.parse(beginDate);
			//定义结束日期
			endDateTime = DateUtils.parseDate(endDate,"yyyy-MM-dd");
		} catch (ParseException e) {
			System.out.println("时间转化异常，请检查你的时间格式是否为yyyy-MM或yyyy-MM-dd");
		}
		//定义日期实例
		Calendar dd = Calendar.getInstance();
		//设置日期起始时间
		dd.setTime(beginDateTime);
		//起始时间正好在季度首月则判断比较日
		int first=1;
		//if (js1 == 1 || js1== 4 || js1 == 7 || js1 == 10) {
			/*//起始时间正好在季度首月则判断比较日
			if(Integer.parseInt(beginDate.substring(beginDate.indexOf("-")+1,beginDate.lastIndexOf("-")))>Integer.parseInt(taskFeedbackTime)){
				first=js1;
			}*/
		//判断开始日期在哪一个季度,然后赋值下个季度首月

		//}
		//判断是否到结束日期
		while (!dd.getTime().after(endDateTime)) {
			Integer js1 = Integer.parseInt(DateUtils.formatDate(dd.getTime(), "MM"));
			if (js1==1||js1==2||js1==3){
				String temp = sdf2.format(dd.getTime())+"-"+"04"+"-"+taskFeedbackTime;
				if(DateUtils.parseDate(temp,"yyyy-MM-dd").getTime()<DateUtils.parseDate(DateUtils.formatDate(endDateTime,"yyyy-MM-dd")).getTime()){
					rangeSet.add(sdf2.format(dd.getTime())+"-"+"04"+"-"+taskFeedbackTime);
				}
			}else if(js1==4||js1==5||js1==6){
				String temp = sdf2.format(dd.getTime())+"-"+"07"+"-"+taskFeedbackTime;
				if(DateUtils.parseDate(temp,"yyyy-MM-dd").getTime()<DateUtils.parseDate(DateUtils.formatDate(endDateTime,"yyyy-MM-dd")).getTime()){
					rangeSet.add(sdf2.format(dd.getTime())+"-"+"07"+"-"+taskFeedbackTime);
				}
			}else if(js1==7||js1==8||js1==9){
				String temp = sdf2.format(dd.getTime())+"-"+"10"+"-"+taskFeedbackTime;
				if(DateUtils.parseDate(temp,"yyyy-MM-dd").getTime()<DateUtils.parseDate(DateUtils.formatDate(endDateTime,"yyyy-MM-dd")).getTime()){
					rangeSet.add(sdf2.format(dd.getTime())+"-"+"10"+"-"+taskFeedbackTime);
				}
			}else if(js1==10||js1==11||js1==12){
				dd.add(Calendar.YEAR, 1);
				dd.setTime(DateUtils.parseDate((DateUtils.formatDate(dd.getTime(),"yyyy")+"-01"+"-01")));
				String temp = sdf2.format(dd.getTime())+"-"+"01"+"-"+taskFeedbackTime;
				if(DateUtils.parseDate(temp,"yyyy-MM-dd").getTime()<DateUtils.parseDate(DateUtils.formatDate(endDateTime,"yyyy-MM-dd")).getTime()){
					rangeSet.add(sdf2.format(dd.getTime())+"-"+"01"+"-"+taskFeedbackTime);
				}
			}
			dd.add(Calendar.MONTH, 1);
		}
		//进行当前日期月份加1
		Set set = new HashSet(rangeSet);
		rangeSet.clear();
		//去重
		rangeSet.addAll(set);
		return rangeSet;
	}

	/**
	 *  根据id更新任务状态
	 * @param
	 * @return
	 */
	public int updateTaskStatus(String id ,String taskStatus){
		DcSupTaskInfo taskInfo = new DcSupTaskInfo();
		taskInfo.setId(id);
		taskInfo.setTaskStatus(taskStatus);
		return dao.updateTaskStatus(taskInfo);

	}

	/**
	 * 分发任务
	 * @param dcSupTaskInfo
	 */
	public void confirm(DcSupTaskInfo dcSupTaskInfo) {
		super.save(dcSupTaskInfo);
		if (StringUtils.isNotBlank(dcSupTaskInfo.getId())) {
			DcSupTaskFeedback deleteFeedback = new DcSupTaskFeedback();
			deleteFeedback.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskFeedbackDao.deleteByEntity(deleteFeedback);
			//插入分解后的反馈时间
			DcSupTaskInfoAdd dcdelete = new DcSupTaskInfoAdd();
			dcdelete.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskInfoAddDao.deleteByEntity(dcdelete);
		}
		batchSaveTaskAddTime(dcSupTaskInfo);
		// 保存上传图片
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_image");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_file");
		distributeOrgTask(dcSupTaskInfo);
	}

	/**
	 * 分发任务
	 * @param dcSupTaskInfo
	 */
	private void distributeOrgTask(DcSupTaskInfo dcSupTaskInfo) {
		String[] orgs = dcSupTaskInfo.getTaskLeaderOrg().split(",");
		String[] orgNames = dcSupTaskInfo.getTaskLeaderOrgName().split(",");
		for (int i = 0; i < orgs.length; i++) {
			DcSupTaskAction dcSupTaskAction = new DcSupTaskAction();
			dcSupTaskAction.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskAction.setLeaderOrgCode(orgs[i]);
			dcSupTaskAction.setLeaderOrgName(orgNames[i]);
			dcSupTaskAction.setTransferFlag("0");
			dcSupTaskAction.setExplainFlag("0");
			dcSupTaskAction.setTaskStatus("1");
			dcSupTaskAction.setCreateBy(EmpUtils.getEmployee().getCreateBy());
			dcSupTaskAction.setCreateDate(new Date());
			dcSupTaskAction.setTaskProgress("3");
			if(StringUtils.equals("4",dcSupTaskInfo.getNormalFlag())){
				dcSupTaskAction.setIsDecompose("1");
			}
			dcSupTaskActionDao.insert(dcSupTaskAction);
			// 3普任务部署:分发任务时，向所有牵头单位的【任务收文员】角色用户发送消息
			// 4秘任务确认后，分发任务时，向所有牵头单位的【任务收文员】角色用户发送消息
			//根据牵头单位查询任务收文员角色的所有人,循环发送
			String org = orgs[i];
			if(!StringUtils.equals("999",dcSupTaskInfo.getTaskTypeCode())) {
				Thread thread = new Thread(() -> {
					List<OfficeUser> userByOrg = dcSupTaskActionDao.getUserByOrg("OTSTRANSFER", org);
					for (OfficeUser user : userByOrg) {
//						PcMsgContent msg = new PcMsgContent();
//						msg.setTitle("提示信息");
//						msg.setContent("您有一个任务:\"" + dcSupTaskInfo.getTaskTitle() + "\"待签收,请及时查看");
//						msg.addButton("任务接收", "/a/audit/taskReceive/list");
//						MsgPushUtils.push(msg, dcSupTaskInfo.getId() + "_" + org, "distribute_deploy", user.getUserCode());
						//发送易政网消息
						MsgDetail msgDetail = new MsgDetail();
						msgDetail.setSendid(UserUtils.getUser().getUserCode());
						msgDetail.setSubjectid(user.getUserCode());
						msgDetail.setMesg("您有一个任务:\"" + dcSupTaskInfo.getTaskTitle() + "\"待签收,请及时登录系统查看");
						lehandYzwPushTask.pushYzwShortMsg(msgDetail);
					}
					//新增待办
					dcSupBacklogService.addOffice("督查督办", "任务接收", "任务待接收", "提示信息"
							, "您有一个任务:" + dcSupTaskInfo.getTaskTitle() + "待签收,请及时查看"
							, "/a/audit/taskReceive/list", org
							, dcSupTaskInfo.getId(), "task_receive", userByOrg
							, dcSupTaskAction.getTaskId(), dcSupTaskAction.getId());
					//任务部署驳回的置为已办
					dcSupBacklogService.doBacklog(dcSupTaskInfo.getId(), "task_deploy");
					//任务确认置为已办
					dcSupBacklogService.doBacklog(dcSupTaskInfo.getId(), "task_confirm");

				});
				thread.start();
			}

			dcSupTaskStatusService.addStatus(dcSupTaskAction.getId(), "1", dcSupTaskAction.getTaskStatus(),
					DictUtils.getDictLabel("dc_task_action_status", dcSupTaskAction.getTaskStatus(), "未知"));

			//--->1查询所有附件fileList
//			List<FileUpload> fileUploadList = FileUploadUtils.findFileUpload(dcSupTaskInfo.getId(), "dcSupTaskInfo_file");
//
//			//---->2复制所有附件类型为dcSupTaskAction_file
//			for (int j = 0; j < fileUploadList.size(); j++) {
//				FileUpload fileUpload = fileUploadList.get(j);
//				fileUpload.setBizType("dcSupTaskAction_file");
//				fileUpload.setBizKey(dcSupTaskAction.getId());
//				fileUpload.setId(null);
//				fileUploadDao.insert(fileUpload);
//			}
			//为每个分发牵头责任单位插入反馈时间段到反馈表
			for (DcSupTaskInfoAdd dcSupTaskInfoAdd : dcSupTaskInfo.getDcSupTaskInfoAddList()) {
				if (dcSupTaskInfoAdd.getFeedbackStartTime() != null && dcSupTaskInfoAdd.getFeedbackEndTime() != null) {
					DcSupTaskFeedback feedback = new DcSupTaskFeedback();
					feedback.setTaskId(dcSupTaskInfo.getId());
					feedback.setActionId(dcSupTaskAction.getId());
					feedback.setFeedbackEndTime(dcSupTaskInfoAdd.getFeedbackEndTime());
					feedback.setFeedbackStartTime(dcSupTaskInfoAdd.getFeedbackStartTime());
					feedback.setFeedbackStatus("-1");
					feedback.setFeedbackRequire(dcSupTaskInfoAdd.getFeedbackRequire());
					dcSupTaskFeedbackDao.insert(feedback);
				}

			}
		}
	}

	public Page<DcSupTaskInfo> confirmListData(DcSupTaskInfo dcSupTaskInfo) {
		Page<DcSupTaskInfo> page = dcSupTaskInfo.getPage();
		page.setList(dao.confirmListData(dcSupTaskInfo));
		return  page;
	}

	public List<Map> officeSercretList() {
		return dao.officeSercretList();
	}

	public Map officeSercretFirst() {
		return dao.officeSercretFirst();
	}

    public Page<DcSupTaskAction> queryKeyPointList(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		Page<DcSupTaskAction> page = dcSupTaskAction.getPage();
		page.setList(dao.queryKeyPointList(dcSupTaskAction));
		return  page;
    }

	public Page<DcSupTaskAction> querySpecialList(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		Page<DcSupTaskAction> page = dcSupTaskAction.getPage();
		page.setList(dao.querySpecialList(dcSupTaskAction));
		return  page;
	}

	public Map leaderStatistics(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		List<Map> maps  = dao.leaderStatistics(dcSupTaskAction);
		Map countAction = new HashMap();
		countAction.put("1",0);
		countAction.put("2",0);
		countAction.put("3",0);
		countAction.put("4",0);
		for(Map map:maps){
			if(StringUtils.equals(map.get("task_progress").toString(),"1")){
				countAction.put("1",map.get("num"));
			}
			if(StringUtils.equals(map.get("task_progress").toString(),"2")){
				countAction.put("2",map.get("num"));
			}
			if(StringUtils.equals(map.get("task_progress").toString(),"3")){
				countAction.put("3",map.get("num"));
			}
			if(StringUtils.equals(map.get("task_progress").toString(),"4")){
				countAction.put("4",map.get("num"));
			}
		}

		return  countAction;
	}

	public Page<DcSupTaskAction> queryChildList(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		Page<DcSupTaskAction> page = dcSupTaskAction.getPage();
		page.setList(dao.queryChildList(dcSupTaskAction));
		return page;
	}

	@Transactional(rollbackFor = Exception.class,readOnly=false)
	public List<String> multiSave(DcSupTaskInfoMulti dcSupTaskInfo) throws Exception {
		// 判断是否选择了审核人
		if (StringUtils.isNotBlank(dcSupTaskInfo.getAuditorCode())) {
			dcSupTaskInfo.setAuditFlag("1");
		}

		// 记录保存的任务id
		List<String> taskIds = new ArrayList<>();

		// 如果是草稿
		if ("1".equals(dcSupTaskInfo.getTaskStatus())) {
			// 遍历所有任务内容
			for(int i = 0;i < dcSupTaskInfo.getFormCount();i++){
				DcSupTaskInfo info = getDcSupTaskInfo(dcSupTaskInfo, i);
				batchSaveTaskAddTime(info);
				taskIds.add(info.getId());
			}
			return taskIds;
		}

		// 秘书一科任务，选择线下审核人，默认审核通过
		if("0000".equals(dcSupTaskInfo.getAuditorCode())){
			dcSupTaskInfo.setTaskStatus(Dict.TaskStatus.STATUS_5);
		}

		// 如果是提交
		for(int i = 0;i < dcSupTaskInfo.getFormCount();i++){
			DcSupTaskInfo info = getDcSupTaskInfo(dcSupTaskInfo, i);
			//判断是否输入督办单位分为特殊流程，一般流程
			if (StringUtils.isNotBlank(dcSupTaskInfo.getTaskSupOrg().get(i))) {
				if(!"0000".equals(dcSupTaskInfo.getAuditorCode())){
					// 设置一个临时变量来记录这条任务放到审核表中时的id，在消息中使用
					String tempAuditId = IdGen.nextId();
					String secretary_general = dcSupTaskAuditService.addAuditInfo(tempAuditId, info.getId(), info.getId(), Dict.TargetType.TYPE_1, Dict.AuditType.TYPE_2,
							info.getAuditorCode(), info.getAuditorName(), null);
					if (StringUtils.isNotBlank(secretary_general)) {
						throw new Exception("过程审核失败");
					}
					// 1秘任务部署，选择审核人（即督办人），向审核人发送消息
//					PcMsgContent msg = new PcMsgContent();
//					msg.setTitle("提示信息");
//					// 任务部署
//					msg.setContent("您有一个任务:\""+dcSupTaskInfo.getTaskTitle()+"\"任务部署待审核,请及时查看");
//					msg.addButton("任务部署审核", "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId);
//					MsgPushUtils.push(msg, tempAuditId, "audit_deploy", dcSupTaskInfo.getAuditorCode());
					//发送易政网消息
					MsgDetail msgDetail = new MsgDetail();
					msgDetail.setSendid(UserUtils.getUser().getUserCode());
					msgDetail.setSubjectid(dcSupTaskInfo.getAuditorCode());
					msgDetail.setMesg("您有一个任务:\""+dcSupTaskInfo.getTaskTitle()+"\"任务部署待审核,请及时登录系统查看");
					lehandYzwPushTask.pushYzwShortMsg(msgDetail);
					//新增待办
					dcSupBacklogService.add("督查督办","任务部署审核","闭环任务部署审核","提示信息"
							,"您有一个任务:" + dcSupTaskInfo.getTaskTitle() + "任务部署待审核,请及时查看"
							,"/a/audit/dcSupTaskAudit/form?id="+tempAuditId,""
							,tempAuditId,"task_audit_deploy",dcSupTaskInfo.getAuditorCode()
							,info.getId(),"");
				}
			}
			batchSaveTaskAddTime(info);
			taskIds.add(info.getId());
			// 选择线下审核人，向每一个任务的科室发确认消息
			if ("0000".equals(dcSupTaskInfo.getAuditorCode())) {
				if (StringUtils.isNotBlank(info.getTaskSupOrg())) {
					// 3秘 任务部署，审核人审核通过，给其他科室发确认任务的消息
					List<SysBasicUser> officeMembers = sysBasicDao.getUserByOfficeAndRole(info.getTaskSupOrg(), "SECRETARY_ONE");
					for (SysBasicUser user : officeMembers) {
//						PcMsgContent msg = new PcMsgContent();
//						msg.setTitle("提示信息");
//						msg.setContent("您有一个任务:\"" + info.getTaskTitle() + "\"待确认,请及时查看");
//						msg.addButton("任务确认", "/a/taskdeploy/dcSupTaskInfo/dcSupTaskConfirmList");
//						MsgPushUtils.push(msg, info.getId() + "_" + info.getTaskSupOrg(), "confirm_deploy", user.getUserCode());
						//发送易政网消息
						MsgDetail msgDetail = new MsgDetail();
						msgDetail.setSendid(UserUtils.getUser().getUserCode());
						msgDetail.setSubjectid(user.getUserCode());
						msgDetail.setMesg("您有一个任务:\"" + info.getTaskTitle() + "\"待确认,请及时登录系统查看");
						lehandYzwPushTask.pushYzwShortMsg(msgDetail);

					}
						//新增待办
						dcSupBacklogService.addBasic("督查督办","任务确认","任务确认","提示信息"
								,"您有一个任务:" + dcSupTaskInfo.getTaskTitle() + "待确认,请及时查看"
								,"/a/taskdeploy/dcSupTaskInfo/dcSupTaskConfirmList",info.getTaskSupOrg()
								,info.getId(),"task_confirm",officeMembers
								,info.getId(),"");
				}
			}
		}
		return taskIds;
	}

	/**
	 * 将附件添加到所有的任务中
	 * @param taskIds
	 */
	public void addAttachmentToAllInfo(List<String> taskIds) {
		// 如果只有一个id，就不用执行下去了
		if (taskIds != null && taskIds.size() > 1) {
			// 根据最后一个infoId获取所有的附件
			String lastId = taskIds.get(taskIds.size() - 1);
			List<Map> fileList = dao.findFilesByTaskId(lastId);
			// 遍历其他任务id，添加附件
			for (String taskId : taskIds) {
				if (!StringUtils.equals(taskId, lastId)) {
					for (Map map : fileList) {
						// 向文件表中插入新数据
						dao.addFiles(UUID.randomUUID().toString(), map.get("file_id").toString(), map.get("file_name").toString(), map.get("file_type").toString(), map.get("file_sort").toString(), taskId, map.get("biz_type").toString(), map.get("status").toString(), map.get("create_by").toString(), DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"), UserUtils.getUser().getUserCode(), DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
					}
				}
			}
		}
	}

	private DcSupTaskInfo getDcSupTaskInfo(DcSupTaskInfoMulti dcSupTaskInfo, int i) throws Exception {
		DcSupTaskInfo  info = new DcSupTaskInfo();
		int j = i+1;
		if(StringUtils.isBlank(dcSupTaskInfo.getTaskContent().get(i))){
			throw new Exception("任务"+j+" : 任务内容不可为空");
		}
		if(dcSupTaskInfo.getTaskStartTime().get(i)==null){
			throw new Exception("任务"+j+" : 开始时间不可为空");
		}
		if(dcSupTaskInfo.getTaskEndTime().get(i)==null){
			throw new Exception("任务"+j+" : 结束时间不可为空");
		}
		if(StringUtils.isBlank(dcSupTaskInfo.getTaskSupUser().get(i))){
			throw new Exception("任务"+j+" : 督办人不可为空");
		}
		if(StringUtils.isBlank(dcSupTaskInfo.getTaskSupOrg().get(i))){
			throw new Exception("任务"+j+" : 督办单位不可为空");
		}
		if(StringUtils.isBlank(dcSupTaskInfo.getTaskLeaderOrg().get(i))){
			throw new Exception("任务"+j+" : 牵头责任单位不可为空");
		}
		if(StringUtils.isNotBlank(dcSupTaskInfo.getSortNum().get(i))&&!StringUtils.isNumeric(dcSupTaskInfo.getSortNum().get(i))){
			throw new Exception("任务"+j+" : 排序编号只能为数字");
		}
		info.setTaskContent(dcSupTaskInfo.getTaskContent().get(i));
		info.setTaskTypeCode(dcSupTaskInfo.getTaskTypeCode());
		info.setTaskYear(dcSupTaskInfo.getTaskYear());
		info.setTaskTypeName(dcSupTaskInfo.getTaskTypeName());
		info.setTaskStatus(dcSupTaskInfo.getTaskStatus());
		info.setTaskTitle(dcSupTaskInfo.getTaskTitle());
		info.setTaskStartTime(dcSupTaskInfo.getTaskStartTime().get(i));
		info.setTaskEndTime(dcSupTaskInfo.getTaskEndTime().get(i));
		info.setTaskSupOrg(dcSupTaskInfo.getTaskSupOrg().get(i));
		info.setTaskSupOrgName(dcSupTaskInfo.getTaskSupOrgName().get(i));
		info.setTaskLeader(dcSupTaskInfo.getTaskLeader().get(i));
		info.setTaskLeaderName(dcSupTaskInfo.getTaskLeaderName().get(i));
		info.setTaskLeaderOrg(dcSupTaskInfo.getTaskLeaderOrg().get(i));
		info.setTaskLeaderOrgName(dcSupTaskInfo.getTaskLeaderOrgName().get(i));
		info.setContactName(dcSupTaskInfo.getContactName().get(i));
		info.setContactPhone(dcSupTaskInfo.getContactPhone().get(i));
		if(dcSupTaskInfo.getFeedbackWay()!=null) {
			info.setFeedbackWay(dcSupTaskInfo.getFeedbackWay().get(i));
		}
		if(dcSupTaskInfo.getFeedbackRate()!=null) {
		info.setFeedbackRate(dcSupTaskInfo.getFeedbackRate().get(i));
		}
		//info.setTaskRequireCode(dcSupTaskInfo.getTaskRequireCode().get(i));
		info.setTaskRequireName(dcSupTaskInfo.getTaskRequireName().get(i));
		info.setMessageNumber(dcSupTaskInfo.getMessageNumber());
		info.setCopyToCode(dcSupTaskInfo.getCopyToCode());
		info.setCopyToName(dcSupTaskInfo.getCopyToName());
		info.setFormFlag(dcSupTaskInfo.getFormFlag());
		info.setAuditorCode(dcSupTaskInfo.getAuditorCode());
		info.setAuditorName(dcSupTaskInfo.getAuditorName());
		info.setTaskCoopOrg(dcSupTaskInfo.getTaskCoopOrg().get(i));
		info.setTaskCoopOrgName(dcSupTaskInfo.getTaskCoopOrgName().get(i));
		info.setTaskSupUser(dcSupTaskInfo.getTaskSupUser().get(i));
		info.setTaskSupUserName(dcSupTaskInfo.getTaskSupUserName().get(i));
		info.setSortNum(dcSupTaskInfo.getSortNum().get(i));
		info.setNormalFlag("2");
		// 获取当前会话对象
		info.setCreateOrg(OfficeUtil.getCurrentOffice().getOfficeCode());
		info.setCreateOrgName(OfficeUtil.getCurrentOffice().getOfficeName());
		Office latestUnit = sysOfficeUnitService.getLatestUnitByOffice();
		info.setCreateUnit(latestUnit.getOfficeCode());
		info.setCreateUnitName(latestUnit.getOfficeName());
		info.setDecomposeFlag("0");
		info.setParentTaskId("0");
		info.setSourceTaskId("0");
		info.setAttachmentFlag(dcSupTaskInfo.getAttachmentFlag());
		uniqueMessageNumber(info);
		super.save(info);
		if(i==0) {
			info.setDcSupTaskInfoAddList(dcSupTaskInfo.getDcSupTaskInfoAddList1());
		}else if(i==1){
			info.setDcSupTaskInfoAddList(dcSupTaskInfo.getDcSupTaskInfoAddList2());
		}else if(i==2){
			info.setDcSupTaskInfoAddList(dcSupTaskInfo.getDcSupTaskInfoAddList3());
		}else if(i==3){
			info.setDcSupTaskInfoAddList(dcSupTaskInfo.getDcSupTaskInfoAddList4());
		}else if(i==4){
			info.setDcSupTaskInfoAddList(dcSupTaskInfo.getDcSupTaskInfoAddList5());
		}
		// 保存上传图片
		FileUploadUtils.saveFileUpload(info, info.getId(), "dcSupTaskInfo_image");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(info, info.getId(), "dcSupTaskInfo_file");
		return info;
	}

	@Transactional(readOnly=false)
	public String importData(MultipartFile file,Boolean normalFlag) {
		if (file == null){
			throw new ServiceException(text("请选择导入的数据文件！"));
		}
		int successNum = 0; int failureNum = 0;
		StringBuilder successMsg = new StringBuilder();
		StringBuilder failureMsg = new StringBuilder();
		try(ExcelImport ei = new ExcelImport(file, 2, 0)){
			List<DcSupTaskInfo> list = ei.getDataList(DcSupTaskInfo.class);
			for (DcSupTaskInfo info : list) {
				try{
					// 验证数据文件
					ValidatorUtils.validateWithException(info);
					// 任务年度为空验证
					if (StringUtils.isBlank(info.getTaskYear())) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：任务年度不能为空");
						continue;
					}
					if (StringUtils.isBlank(info.getTaskTypeName())) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：任务类型不能为空");
						continue;
					}

					if (StringUtils.isBlank(info.getTaskTitle())) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：任务标题不能为空");
						continue;
					}
					if (StringUtils.isBlank(info.getTaskContent())) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：任务内容不能为空");
						continue;
					}
					if (info.getTaskStartTime()==null) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：反馈起始时间不能为空");
						continue;
					}
					if (info.getTaskEndTime()==null) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：反馈截止时间不能为空");
						continue;
					}
					if (StringUtils.isBlank(info.getSortNum())) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：排序编号不能为空");
						continue;
					}
					String type = "";
					DcSupTaskInfoDict dcSupTaskInfoDict = new DcSupTaskInfoDict();
					dcSupTaskInfoDict.setDictStatus("0");
					dcSupTaskInfoDict.setDictLabel(info.getTaskTypeName());
					DcSupTaskInfoDict dcSupTaskInfoDict1 = dcSupTaskInfoDictService.getValue(dcSupTaskInfoDict);
					if(dcSupTaskInfoDict1!=null){
						type=dcSupTaskInfoDict1.getDictValue();
					}
					if (StringUtils.isBlank(type)) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：系统没有此任务类型");
						continue;
					}
					if (info.getContactName().length()>64) {
						failureNum++;
						failureMsg.append("<br/>" + failureNum + " 导入失败：联系人过长");
						continue;
					}
					if(StringUtils.isNotBlank(info.getContactPhone())){
						String regex = "^1[345678]\\d{9}$";
						Pattern pattern = Pattern.compile(regex);
						Matcher matcher = pattern.matcher(info.getContactPhone());
						if (!matcher.matches()) {
							failureNum++;
							failureMsg.append("<br/>" + failureNum + " 导入失败：手机号码格式不正确");
							continue;
						}
					}
					// 验证是否存在这个用户
					    info.setTaskStatus("1");
					    info.setTaskTypeCode(type);
					    info.setNormalFlag("1");
						// 获取当前会话对象
						info.setCreateOrg(OfficeUtil.getCurrentOffice().getOfficeCode());
						info.setCreateOrgName(OfficeUtil.getCurrentOffice().getOfficeName());
						Office latestUnit = sysOfficeUnitService.getLatestUnitByOffice();
						info.setCreateUnit(latestUnit.getOfficeCode());
						info.setCreateUnitName(latestUnit.getOfficeName());
					    if(normalFlag){
							info.setNormalFlag("2");
						}
						this.save(info);
						successNum++;
						successMsg.append("<br/>" + successNum + "、任务 " + info.getTaskTitle() + " 导入成功");

				} catch (Exception e) {
					failureNum++;
					String msg = "<br/>" + failureNum + "、任务 " + info.getTaskTitle() + " 导入失败：";
					if (e instanceof ConstraintViolationException){
						ConstraintViolationException cve = (ConstraintViolationException)e;
						for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
							msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
						}
					}else{
						msg += e.getMessage();
					}
					failureMsg.append(msg);
					logger.error(msg, e);
				}
			}
		} catch (Exception e) {
			failureMsg.append(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		if (failureNum > 0) {
			failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
			throw new ServiceException(failureMsg.toString());
		}else{
			successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
		}
		return successMsg.toString();
	}

	public Integer getMaxSortNum() {
		return 	dao.getMaxSortNum();
	}

    public String getMsgNumSQE() {
		return  dao.getMsgNumSQE();
    }

	public Integer getMaxMessageNumber() {
		return  dao.getMaxMessageNumber();
	}
	public DcSupTaskInfoMsgNum getMaxMessageNumberByType(DcSupTaskInfoMsgNum dcSupTaskInfoMsgNum) {
		return  dao.getMaxMessageNumberByType(dcSupTaskInfoMsgNum);
	}

	/**
	 * 新增任务时，校验督办字号
	 * @param dcSupTaskInfo
	 */
	public void uniqueMessageNumber(DcSupTaskInfo dcSupTaskInfo){
		String messageNumber = dcSupTaskInfo.getMessageNumber();
		String title = dcSupTaskInfo.getTaskTitle();
		String normalFlag = dcSupTaskInfo.getNormalFlag();
		if (StringUtils.inString(normalFlag, Dict.TaskNormalFlag.FLAG_1, Dict.TaskNormalFlag.FLAG_3)) {
			DcSupTaskInfo t = new DcSupTaskInfo();
			t.setId(dcSupTaskInfo.getId());
			t.setMessageNumber(messageNumber);
			t.setNormalFlag(normalFlag);
			Integer  count  = dao.isUniquemessageNumber(t);
			if(count!=null && count>0){
				throw new ServiceException("督办字号已存在");
			}
		}else{
//			//效验标题
//			DcSupTaskInfo  dstif=new DcSupTaskInfo();
//			dstif.setTaskTitle(title);
//			dstif.setNormalFlag(normalFlag);
//			dstif= dao.ExistTitle(dstif);
//			if(dstif!=null){
//				if(dstif.getMessageNumber()!=null && messageNumber != null){
//					if(!StringUtils.equals(messageNumber,dstif.getMessageNumber())){
//						throw new ServiceException("相同标题督办字号必须一样");
//					}
//				}
//			}
//			//效验督办字号
//			DcSupTaskInfo  dstifes=new DcSupTaskInfo();
//			dstifes.setMessageNumber(messageNumber);
//			dstifes.setNormalFlag(normalFlag);
//			dstifes= dao.ExistTitle(dstifes);
//			if(dstifes !=null){
//				if(!StringUtils.equals(dstifes.getTaskTitle(),title)){
//					throw new ServiceException("相同督办字号标题必须一样");
//				}
//			}

		}
	}

	public List<Map> queryOrgLastedFeedBackContentList(String taskId) {
		List<String>  actionLists = dao.queryActionList(taskId);
		List<Map> maps = new ArrayList<>();
		if(actionLists != null){
			for(String id:actionLists){
				Map map =  dao.queryOrgLastedFeedBackContentList(id,taskId);
				if(map != null){
					List<Map> fileList = dao.findFilesByTaskId(map.get("id").toString());
					map.put("fileList",fileList);
				    maps.add(map);
				}
			}
		}
		return maps;
	}

	public Page<DcSupTaskInfo> queryWorkList(DcSupTaskInfo dcSupTaskInfo) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskInfo.getTimeParam());
		if(times != null) {
			dcSupTaskInfo.setStartTime(times.get(0));
			dcSupTaskInfo.setEndTime(times.get(1));
		}
		Page<DcSupTaskInfo> page = dcSupTaskInfo.getPage();
		page.setList(dao.queryWorkList(dcSupTaskInfo));
		return  page;
	}

	public void deleteById(DcSupTaskInfo dcSupTaskInfo) {
		super.delete(dcSupTaskInfo);
	}

	public void updateTaskProgress(String id) {
		dao.updateTaskProgress(id);
	}

	public Map getRedBlue(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		List<DcSupTaskAction> list = dao.getRedBlue(dcSupTaskAction);
		Map countAction = new HashMap();
		//feedback_progress 1序时推进、2滞后时序、3已完成、4未完成
		Integer one = 0;//进度滞后 包含的数据为任务反馈最后一次状态为进度滞后和未完成状态
		Integer two = 0;//逾期反馈 逾期未反馈，包含的数据为任务反馈最后一次状态为逾期未反馈
		Integer three = 0;//序时推进 包含的数据为任务反馈最后一次状态为序时推进
		Integer four = 0;//已完成 包含的数据为任务反馈最后一次状态为已完成
		for(DcSupTaskAction map:list){
			if(map.getNum()==null){ map.setNum(0); }
			if((map.getNum()==2||map.getNum()==4)&&map.getNum1()==0){
				one++;
			}

			if(map.getNum1()==1){
				two++;
			}
			if(map.getNum()==1&&map.getNum1()==0){
				three++;
			}

			if(map.getNum()==3&&map.getNum1()==0){
				four++;
			}
		}
		countAction.put("1",one);
		countAction.put("2",two);
		countAction.put("3",three);
		countAction.put("4",four);
		return countAction;
	}

	/**
	 * 市领导最新上面统计数目 2023/2/23
	 * @param dcSupTaskAction
	 * @return
	 */
	public Map getLeaderStatics(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		List<DcSupTaskAction> list = dao.getRedBlue(dcSupTaskAction);
		Map countAction = new HashMap();
		//feedback_progress 1序时推进、2滞后时序、3已完成、4未完成
		Integer one = 0;//进度滞后 包含的数据为任务反馈最后一次状态为进度滞后和未完成状态
		Integer two = 0;//逾期反馈 逾期未反馈，包含的数据为任务反馈最后一次状态为逾期未反馈
		Integer three = 0;//序时推进 包含的数据为任务反馈最后一次状态为序时推进
		Integer four = 0;//已完成 包含的数据为任务反馈最后一次状态为已完成
		for(DcSupTaskAction action:list){
			if(StringUtils.equals( action.getTaskProgress(),"1") ){
				one++;
			}
			else if(StringUtils.equals( action.getTaskProgress(),"2") ){
				two++;
			}
			else if(StringUtils.equals( action.getTaskProgress(),"3") ){
				three++;
			}
			else if(StringUtils.equals( action.getTaskProgress(),"4") ){
				four++;
			}

		}
		countAction.put("1",one);
		countAction.put("2",two);
		countAction.put("3",three);
		countAction.put("4",four);
		return countAction;
	}




	public Page<DcSupTaskAction> queryChildList2(DcSupTaskAction dcSupTaskAction) {
		List<String> times = DateTimeUtil.timeString(dcSupTaskAction.getTimeParam());
		if(times != null) {
			dcSupTaskAction.setStartTime(times.get(0));
			dcSupTaskAction.setEndTime(times.get(1));
		}
		Page<DcSupTaskAction> page = dcSupTaskAction.getPage();
		DcSupTaskAction action = new DcSupTaskAction();
		action.setStartTime(dcSupTaskAction.getStartTime());
		action.setEndTime(dcSupTaskAction.getEndTime());
		action.setTaskLeader(dcSupTaskAction.getTaskLeader());
		action.setTaskTitle(dcSupTaskAction.getTaskTitle());
		action.setTaskContent(dcSupTaskAction.getTaskContent());
		List<DcSupTaskAction> dcSupTaskActions = dao.queryChildList2(action);
		List<DcSupTaskAction> res = new ArrayList<>();
		Integer pageNum = page.getPageNo()-1;
		Integer pageNum1 = pageNum*20;
		Integer pageNum2 = (pageNum+1)*20;
		Integer pageNum3 = 0;
		for (DcSupTaskAction act:dcSupTaskActions) {
			if(act.getNum()==null){ act.setNum(0); }
				if(dcSupTaskAction.getTaskProgress().equals("1")){
					if((act.getNum().toString().equals("2")||act.getNum().toString().equals("4"))&&act.getNum1()==0){
						if(pageNum1<=pageNum3&&pageNum3<pageNum2){
							act.setNum(1);
							res.add(act);
						}
						pageNum3++;
					}
				}else if(dcSupTaskAction.getTaskProgress().equals("2")){
					if(act.getNum1().toString().equals("1")){
						if(pageNum1<=pageNum3&&pageNum3<pageNum2){
							act.setNum(2);
							res.add(act);
						}
						pageNum3++;
					}
			}else if(dcSupTaskAction.getTaskProgress().equals("3")){
				if(act.getNum().toString().equals("1")&&act.getNum1()==0){
					if(pageNum1<=pageNum3&&pageNum3<pageNum2){
						act.setNum(3);
						res.add(act);
					}
					pageNum3++;
				}
			}else if(dcSupTaskAction.getTaskProgress().equals("4")){
				if(act.getNum().toString().equals("3")&&act.getNum1()==0){
					if(pageNum1<=pageNum3&&pageNum3<pageNum2){
						act.setNum(4);
						res.add(act);
					}
					pageNum3++;
				}
			}
		}
		page.setCount(pageNum3);
		page.setList(res);
		return page;
	}
	@Transactional(readOnly=false)
	public void saveDeCompose(DcSupTaskInfo dcSupTaskInfo) {
		Office latestUnit = sysOfficeUnitService.getLatestUnitByOffice();
		dcSupTaskInfo.setCreateUnit(latestUnit.getOfficeCode());
		dcSupTaskInfo.setCreateUnitName(latestUnit.getOfficeName());
		dcSupTaskInfo.setAuditFlag("1");
		DcSupTaskAction action = new DcSupTaskAction();
		action.setId(dcSupTaskInfo.getRemarks3());
		dcSupTaskInfo.setDecomposeFlag("1");
		dcSupTaskInfo.setNormalFlag("4");
		super.insert(dcSupTaskInfo);
		// 保存上传附件
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_file");
		action.setDecomposeTaskId(dcSupTaskInfo.getId());
		dcSupTaskActionDao.update(action);
		if (StringUtils.isNotBlank(dcSupTaskInfo.getId())) {
			DcSupTaskFeedback deleteFeedback = new DcSupTaskFeedback();
			deleteFeedback.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskFeedbackDao.deleteByEntity(deleteFeedback);
			//插入分解后的反馈时间
			DcSupTaskInfoAdd dcdelete = new DcSupTaskInfoAdd();
			dcdelete.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskInfoAddDao.deleteByEntity(dcdelete);
		}
		distributeOrgTask(dcSupTaskInfo);
		//插入分解后的反馈时间
		if(StringUtils.isNotBlank(dcSupTaskInfo.getId())){
			DcSupTaskInfoAdd dcdelete = new DcSupTaskInfoAdd();
			dcdelete.setTaskId(dcSupTaskInfo.getId());
			dcSupTaskInfoAddDao.deleteByEntity(dcdelete);
		}
		for (DcSupTaskInfoAdd dcSupTaskInfoAdd : dcSupTaskInfo.getDcSupTaskInfoAddList()) {
			if (dcSupTaskInfoAdd.getFeedbackStartTime() != null && dcSupTaskInfoAdd.getFeedbackEndTime() != null) {
				dcSupTaskInfoAdd.setTaskId(dcSupTaskInfo.getId());
				dcSupTaskInfoAdd.setId(null);
				dcSupTaskInfoAddDao.insert(dcSupTaskInfoAdd);
			}

		}
	}
	@SneakyThrows
	@Transactional(readOnly=false)
	public void onPublish(DcSupTaskInfo dcSupTaskInfo) {
		// 获取需要一键发布的任务列表
		List<DcSupTaskInfo> list = dao.findListPage(dcSupTaskInfo);
		// 构建消息列表，使用map是为了过滤相同的审核人
		Map<String, DcSupTaskInfo> pushMsgList = new HashMap<>();
		// 构建待通知用户列表
		List<SysBasicUser> officeMembers = null;
		// 遍历任务
		for (DcSupTaskInfo info : list) {
			// 修改任务状态
			info.setTaskStatus("2");
			// 获取任务审核人
			String auditorCode = info.getAuditorCode();
			if ("0000".equals(auditorCode)) {
				// 如果是线下审核，直接审核通过
				info.setTaskStatus(Dict.TaskStatus.STATUS_5);
				if (StringUtils.isNotBlank(info.getTaskSupOrg())) {
					// 获取其他科室成员
					officeMembers = sysBasicDao.getUserByOfficeAndRole(info.getTaskSupOrg(), "SECRETARY_ONE");
					// 给其他科室成员发送信息
					if (officeMembers != null && officeMembers.size() > 0) {
						for (SysBasicUser user : officeMembers) {
//							PcMsgContent msg = new PcMsgContent();
//							msg.setTitle("提示信息");
//							msg.setContent("您有一个任务:\"" + info.getTaskTitle() + "\"待确认,请及时查看");
//							msg.addButton("任务确认", "/a/taskdeploy/dcSupTaskInfo/dcSupTaskConfirmList");
//							MsgPushUtils.push(msg, info.getId() + "_" + info.getTaskSupOrg(), "confirm_deploy", user.getUserCode());
							//发送易政网消息
							MsgDetail msgDetail = new MsgDetail();
							msgDetail.setSendid(UserUtils.getUser().getUserCode());
							msgDetail.setSubjectid(user.getUserCode());
							msgDetail.setMesg("您有一个任务:\"" + info.getTaskTitle() + "\"待确认,请及时登录系统查看");
							lehandYzwPushTask.pushYzwShortMsg(msgDetail);
						}
						//新增待办
						dcSupBacklogService.addBasic("督查督办","任务确认","任务确认","提示信息"
								,"您有一个任务:" + info.getTaskTitle() + "待确认,请及时查看"
								,"/a/taskdeploy/dcSupTaskInfo/dcSupTaskConfirmList",info.getTaskSupOrg()
								,info.getId(),"task_confirm",officeMembers
								,info.getId(),"");
					}
				}
			} else {
				// 如果选择了审核人
				// 向审核表中插入数据
				String tempAuditId = IdGen.nextId();
				String secretary_general = dcSupTaskAuditService.addAuditInfo(tempAuditId, info.getId(), info.getId(), Dict.TargetType.TYPE_1, Dict.AuditType.TYPE_2,
						info.getAuditorCode(), info.getAuditorName(), null);
				//任务发起,创建审核待办
				dcSupBacklogService.add("督查督办","任务部署审核","闭环任务一键发布审核","提示信息"
						,"您有一个任务:" + info.getTaskTitle() + "任务部署待审核,请及时查看"
						,"/a/audit/dcSupTaskAudit/list?auditType=deploy&type=wait",""
						,tempAuditId,"task_audit_deploy",info.getAuditorCode()
						,info.getId(),"");
				if (StringUtils.isNotBlank(secretary_general)) {
					throw new Exception("过程审核失败");
				}
				// 记录审核信息，会过滤审核人相同的信息
				pushMsgList.put(info.getAuditorCode(), info);
			}
			//置为已办
			dcSupBacklogService.doBacklog(info.getId(),"task_deploy");
			dao.update(info);
		}

		// 给审核人发送信息
		for (DcSupTaskInfo info : pushMsgList.values()) {
			// 1秘任务部署，选择审核人（即督办人），向审核人发送消息
			PcMsgContent msg = new PcMsgContent();
			msg.setTitle("提示信息");
			// 任务部署
			msg.setContent("您有一个任务:\"" + info.getTaskTitle() + "\"任务部署待审核,请及时查看");
			// 此处如有多次审核，只会展示最后一次，因此让他跳转到列表中
			msg.addButton("任务部署审核", "/a/audit/dcSupTaskAudit/list?auditType=deploy&type=wait");
			MsgPushUtils.push(msg, info.getId(), "audit_deploy", info.getAuditorCode());
			//发送易政网消息
			MsgDetail msgDetail = new MsgDetail();
			msgDetail.setSendid(UserUtils.getUser().getUserCode());
			msgDetail.setSubjectid(info.getAuditorCode());
			msgDetail.setMesg("您有一个任务:\"" + info.getTaskTitle() + "\"任务部署待审核,请及时登录系统查看");
			lehandYzwPushTask.pushYzwShortMsg(msgDetail);
		}

	}

	public Page<DcSupTaskInfo> queryDeleteListData(DcSupTaskInfo dcSupTaskInfo) {
		Page<DcSupTaskInfo> page = dcSupTaskInfo.getPage();
		page.setList(dao.queryDeleteListData(dcSupTaskInfo));
		return page;
	}

	public void deleteAll(DcSupTaskInfo dcSupTaskInfo) {
		dao.deleteAll(dcSupTaskInfo.getId());
		dao.deleteAll1(dcSupTaskInfo.getId());
		dao.deleteAll2(dcSupTaskInfo.getId());
		dao.deleteAll3(dcSupTaskInfo.getId());
		dao.deleteAll4(dcSupTaskInfo.getId());
		dao.deleteAll5(dcSupTaskInfo.getId());
		dao.deleteAll6(dcSupTaskInfo.getId());
		dao.deleteAll7(dcSupTaskInfo.getId());
	}

    public Object getActionFeedback(String id) {
		return dao.getActionFeedback(id);
    }
	/**
	 * 同步数据到两张表
	 */
	@Transactional(readOnly=false)
	public void syncTaskActionAndFeedBack(){
		//同步action
		Date maxDate = dcSupTaskInfoSyncDao.findMaxSyncActionTime();
		List<Map<String,Object>> actionList= dao.findTaskActionList(maxDate);
		for(Map action :actionList){
			dcSupTaskInfoSyncDao.insertSyncTaskAction(action);
		}
		//同步feedback
		Date maxFeedbackTime = dcSupTaskInfoSyncDao.findMaxSynFeedbackTime();
		List<Map<String,Object>> feedbackList= dao.findfeedbackList(maxFeedbackTime);
		for(Map feedback :feedbackList){
			dcSupTaskInfoSyncDao.insertSyncFeedback(feedback);
		}
	}

    public Date minFeedbackEndTime(String taskNo) {
		return dao.minFeedbackEndTime(taskNo);
    }
	@Transactional(readOnly=false)
	public void savefollowOrg(DcSupTaskInfo dcSupTaskInfo, String unitCodes, String unitNames) {
		DcSupTaskInfo dcSupTaskInfo_update = new DcSupTaskInfo();
		dcSupTaskInfo_update.setId(dcSupTaskInfo.getId());
		dcSupTaskInfo_update.setTaskLeaderOrg(dcSupTaskInfo.getTaskLeaderOrg()+","+unitCodes);
		dcSupTaskInfo_update.setTaskLeaderOrgName(dcSupTaskInfo.getTaskLeaderOrgName()+","+unitNames);
		super.save(dcSupTaskInfo_update);
		dcSupTaskInfo.setTaskLeaderOrg(unitCodes);
		dcSupTaskInfo.setTaskLeaderOrgName(unitNames);
		distributeOrgTask(dcSupTaskInfo);
	}
	/**
	 * 根据actionId查询出info表信息
	 * @param actionId
	 * @return
	 */
	public DcSupTaskInfo queryInfoByActionId(String actionId){
		return dao.queryInfoByActionId(actionId);
	}

	public void saveEditAllInfo(DcSupTaskInfo dcSupTaskInfo) {
		super.save(dcSupTaskInfo);
		FileUploadUtils.saveFileUpload(dcSupTaskInfo, dcSupTaskInfo.getId(), "dcSupTaskInfo_file");
	}
}